package com.kaiyiweitong.tongxing.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.kaiyiweitong.tongxing.R;
import com.zhy.view.flowlayout.FlowLayout;

import java.util.List;

/**
 * Created by Administrator on 2017/12/20 0020.
 */

public class ServiceTagAdapter extends com.zhy.view.flowlayout.TagAdapter<String> {

    private int mCurrentPosition = 0;
    private onClickListener mListener;

    public interface onClickListener {
        void onClick(FlowLayout layout,int position);
    }

    public ServiceTagAdapter(List<String> data, onClickListener listener) {
        super(data);
        mListener = listener;
    }

    @Override
    public View getView(final FlowLayout parent, final int position, String s) {
      TextView tv = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.tag_service_info,
                null, false);
        tv.setText(s);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.onClick(parent,position);
                if (position != mCurrentPosition) {
                    parent.getChildAt(position).setSelected(true);
                    parent.getChildAt(mCurrentPosition).setSelected(false);
                    mCurrentPosition = position;
                }
            }
        });
        return tv;
    }
}
